using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.IO;

namespace WinSAG
{
    [DefaultPropertyAttribute("Name"), Serializable()]
    public class ProjectProperties : ICloneable, IGridProperties
    {
        // Project properties
        private string projectName;
        private string projectPath;
        private string projectCreatedDate;
        private string projectFileName;
        private string srcFilePath;

        // Tool options
        private bool balanceCurlyBraces;
        private bool balanceParentheses;
        private bool balanceSquareBrackets;
        private string ignoreBlocks;
        private bool ignoreCharacterCase=true;
        private bool ignoreCharacters;
        private bool ignoreCurlyBraces=true;
        private bool ignoreIdentifierCase=true;
        private bool ignoreIdentifiers;
        private bool ignoreLiterals;
        private bool ignoreModifiers=true;
        private bool ignoreNumbers;
        private bool ignoreRegions;
        private bool ignoreStringCase=true;
        private bool ignoreStrings;
        private bool ignoreSubtypeNames;
        private bool ignoreVariableNames;
        private bool reportDuplicateText;

        private string excludes;
        private string includes="*.*";
        private string language;
        private int threshold=6;

        // config, outputfmtter are not included

        public ProjectProperties()
        {
            projectCreatedDate = DateTime.Now.ToString();
        }

        //
        // Property grid variables
        //
        [CategoryAttribute("Project"), DefaultValueAttribute("New project"), DescriptionAttribute("Project name")]
        public string ProjectName 
        {
            get { return projectName; }
            set { projectName = value; }
        }

        [CategoryAttribute("Project"), DefaultValueAttribute("project.xml"), DescriptionAttribute("Project file name")]
        public string ProjectFileName
        {
            get { return projectFileName;  }
            set 
            {
                projectFileName = Path.GetFileName(value);
                projectPath = Path.GetDirectoryName(value);
            }
        }

        [EditorAttribute(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor)), 
        CategoryAttribute("Project"), DescriptionAttribute("Source file path. Select the folder where the files to be checked are present. Recursive is ON by default.")]
        public string SourcePath
        {
            get { return srcFilePath; }
            set
            {
                srcFilePath = value;
            }
        }
        [CategoryAttribute("Project"), ReadOnlyAttribute(true), DescriptionAttribute("Project creation date (readonly)")]
        public string ProjectCreatedOn
        {
            get { return projectCreatedDate;  }
        }

        [CategoryAttribute("Project"), ReadOnlyAttribute(true), DescriptionAttribute("Project folder (readonly)")]
        public string ProjectFileFolder
        {
            get { return projectPath; }
        }

        [CategoryAttribute("Tool Options"), DefaultValueAttribute(false), DescriptionAttribute("Accounts for curly braces when breaking lines")]
        public bool BalanceCurlyBraces
        {
            set { balanceCurlyBraces = value; }
            get { return balanceCurlyBraces;  }
        }

        [CategoryAttribute("Tool Options"), DefaultValueAttribute(false), DescriptionAttribute("Accounts for parentheses when breaking lines")]
        public bool BalanceParentheses
        {
            set { balanceParentheses = value; }
            get { return balanceParentheses;  }
        }

        [CategoryAttribute("Tool Options"), DefaultValueAttribute(false), DescriptionAttribute("Accounts for square brackets when breaking lines")]
        public bool BalanceSquareBrackets
        {
            set { balanceSquareBrackets = value; }
            get { return balanceSquareBrackets; }
        }

        [CategoryAttribute("Tool Options"), DefaultValueAttribute(""), DescriptionAttribute("Ignores all lines in the block between START/END")]
        public string IgnoreBlocks
        {
            set { ignoreBlocks = value; }
            get { return ignoreBlocks; }
        }

        [CategoryAttribute("Tool Options"), DefaultValueAttribute(true), DescriptionAttribute("Matches character literals irrespective of case")]
        public bool IgnoreCharacterCase
        {
            set { ignoreCharacterCase = value; }
            get { return ignoreCharacterCase; }
        }

        [CategoryAttribute("Tool Options"), DefaultValueAttribute(false), DescriptionAttribute("Completely ignores character literals")]
        public bool IgnoreCharacters
        {
            set { ignoreCharacters = value; }
            get { return ignoreCharacters; }
        }

        [CategoryAttribute("Tool Options"), DefaultValueAttribute(true), DescriptionAttribute("Completely ignores curly braces")]
        public bool IgnoreCurlyBraces
        {
            set { ignoreCurlyBraces = value; }
            get { return ignoreCurlyBraces; }
        }

        [CategoryAttribute("Tool Options"), DefaultValueAttribute(true), DescriptionAttribute("Matches identifiers irresepctive of case")]        
        public bool IgnoreIdentifierCase
        {
            set { ignoreIdentifierCase = value; }
            get { return ignoreIdentifierCase; }
        }

        [CategoryAttribute("Tool Options"), DefaultValueAttribute(false), DescriptionAttribute("Completely ignores identifiers")]
        public bool IgnoreIdentifiers
        {
            set { ignoreIdentifiers = value; }
            get { return ignoreIdentifiers; }
        }

        [CategoryAttribute("Tool Options"), DefaultValueAttribute(false), DescriptionAttribute("Completely ignores all literals (strings, numbers and characters)")]
        public bool IgnoreLiterals
        {
            set { ignoreLiterals = value; }
            get { return ignoreLiterals; }
        }

        [CategoryAttribute("Tool Options"), DefaultValueAttribute(true), DescriptionAttribute("Ignores modifiers (public, private, static, etc.)")]        
        public bool IgnoreModifiers
        {
            set { ignoreModifiers = value; }
            get { return ignoreModifiers; }
        }

        [CategoryAttribute("Tool Options"), DefaultValueAttribute(false), DescriptionAttribute("Completely ignores numbers")]
        public bool IgnoreNumbers
        {
            set { ignoreNumbers = value; }
            get { return ignoreNumbers; }
        }

        [CategoryAttribute("Tool Options"), DefaultValueAttribute(false), DescriptionAttribute("Ignores all lines between #region/#endregion")]
        public bool IgnoreRegions
        {
            set { ignoreRegions = value; }
            get { return ignoreRegions; }
        }

        [CategoryAttribute("Tool Options"), DefaultValueAttribute(true), DescriptionAttribute("Matches string literals irrespective of case")]
        public bool IgnoreStringCase
        {
            set { ignoreStringCase = value; }
            get { return ignoreStringCase; }
        }

        [CategoryAttribute("Tool Options"), DefaultValueAttribute(false), DescriptionAttribute("Completely ignores the contents of strings")]
        public bool IgnoreStrings
        {
            set { ignoreStrings = value; }
            get { return ignoreStrings; }
        }

        [CategoryAttribute("Tool Options"), DefaultValueAttribute(false), DescriptionAttribute("Matches on similar type names (eg. Reader and FilterReader)")]
        public bool IgnoreSubtypeNames
        {
            set { ignoreSubtypeNames = value; }
            get { return ignoreSubtypeNames; }
        }

        [CategoryAttribute("Tool Options"), DefaultValueAttribute(false), DescriptionAttribute("Completely ignores variable names (fields, parameters and locals)")]
        public bool IgnoreVariableNames
        {
            set { ignoreVariableNames = value; }
            get { return ignoreVariableNames; }
        }

        [CategoryAttribute("Tool Options"), DefaultValueAttribute(true), DescriptionAttribute("Prints the duplicate text in reports")]
        public bool ReportDuplicateText
        {
            set { reportDuplicateText = value; }
            get { return reportDuplicateText; }
        }

        [CategoryAttribute("Tool Options"), DefaultValueAttribute(null), DescriptionAttribute("Excludes files matching the specified pattern")]
        public string ExcludeFiles
        {
            set { excludes = value; }
            get { return excludes; }
        }

        [CategoryAttribute("Tool Options"), DefaultValueAttribute("*.*"), 
        DescriptionAttribute("Include files matching the specified pattern.\n*****[ NOTE ]*****\n If *.* is mentioned here, be sure to throttle ToolMaxExecutionTime parameter, as SAT may need more time to process all the files.")]
        public string IncludeFiles
        {
            set { includes = value; }
            get { return includes; }
        }

        [CategoryAttribute("Tool Options"), DefaultValueAttribute("C/C++"), DescriptionAttribute("Assumes ALL files are in the specified language")]
        public string Language
        {
            set { language = value; }
            get { return language; }
        }

        [CategoryAttribute("Tool Options"), DefaultValueAttribute(6), DescriptionAttribute("Matches will contain at least the specified number of lines")]
        public int ComparisonThreshold
        {
            set { threshold = value; }
            get { return threshold; }
        }

        #region ICloneable Members

        public object Clone()
        {
            // Cloning is shallow - TODO: Check if this is enuf or more needed. 
            ProjectProperties pp = this.MemberwiseClone() as ProjectProperties;
            return pp;
        }

        #endregion

        #region IGridProperties Members

        private bool dirtyFlag = false;

        public void setDirty(bool v)
        {
            dirtyFlag = v;
        }

        public bool IsDirty()
        {
            return dirtyFlag;
        }

        public string getObjectName()
        {
            return @"Project Properties";
        }

        #endregion
    }
}
